package com.template.entity.markdown;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import static com.template.utlis.StringCommons.*;
import static com.template.utlis.StringCommons.FlexModeEnum.STRETCH;
import static com.template.utlis.StringCommons.TagEnum.COLUMN_SET;

/**
 * @author wangqi
 * @date 2024-01-18 15:50
 */
public class ColumnSet {
    private JSONObject columnSet;
    private JSONArray columns;

    public static ColumnSet create() {
        return new ColumnSet();
    }

    public static ColumnSet createDefault() {
        return ColumnSet.create().backgroundStyle(BackgroundStyleEnum.GREY).flexMode(STRETCH).horizontalSpacingSmall();
    }

    public ColumnSet() {
        this.columnSet = new JSONObject();
        this.columns = new JSONArray();
        this.columnSet.put(TAG, COLUMN_SET.getValue());
    }

    public  ColumnSet addDefaultLine(String content){
        return this.addColumn( Column.create().addMarkdownElement(MarkdownElement.create().content(content).textAlign(TextAlignEnum.CENTER)).width(WeightEnum.ONE).verticalAlign(VerticalAlignEnum.CENTER));
    }
    public ColumnSet flexMode(FlexModeEnum flexModeEnum) {
        this.columnSet.put(FLEX_MODE, flexModeEnum == null ? FlexModeEnum.NONE.getValue() : flexModeEnum.getValue());
        return this;
    }

    public ColumnSet backgroundStyle(BackgroundStyleEnum backgroundStyleEnum) {
        this.columnSet.put(BACKGROUND_STYLE, backgroundStyleEnum == null ? BackgroundStyleEnum.DEFAULT.getValue() : backgroundStyleEnum.getValue());
        return this;
    }

    public ColumnSet horizontalSpacingSmall() {
        this.columnSet.put(HORIZONTAL_SPACING, SMALL);
        return this;
    }

    public ColumnSet addColumn(Column column) {
        this.columns.add(column.build());
        return this;
    }

    public JSONObject build() {
        columnSet.put(COLUMNS, columns);
        return columnSet;
    }
}
